package com.dmitriyp.movie.console.actions;

import static java.lang.System.out;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.dmitriyp.movie.console.AbstractUserAction;
import com.dmitriyp.movie.dao.IMovieManager;
import com.dmitriyp.movie.implementation.MovieImporter;
import com.dmitriyp.movie.mapping.Movie;

public class UserImportAction extends AbstractUserAction {

	public UserImportAction(IMovieManager manager) {
		super(manager);
	}

	public void doAction() {
		out.println("Enter file path:");
		String path = scanner.next();
		MovieImporter importer = new MovieImporter(path);
		try {
			List<Movie> movies = importer.getMovies();
			getManager().addAll(movies);
		} catch (ParserConfigurationException e) {
			out.println(e.getMessage());
		} catch (SAXException e) {
			out.println(e.getMessage());
		} catch (IOException e) {
			out.println(e.getMessage());
		}
	}

}
